import JSEncrypt from "jsencrypt";

// 定义加密函数
export const encryptData = (data: string): string => {
  const encrypt = new JSEncrypt();
  encrypt.setPublicKey(publicKey); // 设置公钥
  const newEncrypt = encrypt.encrypt(data) // 返回加密后的数据，若加密失败，返回 false
  if (newEncrypt === false) {
    throw new Error("加密错误");
  }
  return newEncrypt;
};

const publicKey: string = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnAnwvo0eoD9YRlt/HSfXf/j3GmTpVEM9TdjkwFNSIOhT9/pd3rGPaomCFoVAjWGvFZZYlyLXqF9+7xaBOy+aPvKC8Ih4Cm5P9/nXp+0QdfZ1v6+q8MPmFp7hx0yxag2KhUOO2B7vCPHgGp0mdOIpb9uOzlENmATgrf4SWLE2tfdTJ6+Rt1Oo96HfsmGLdwp6qzN2+9Q1A2P56KVV5Vo2G5OZKwpKDTlyPQXq4KPtCw7lIcSshDcjS+MRBzi/Sg5ebUNkQmb7UTOVnp2fsBK7zcFx4qBDqfIhZVweuvCZBJjNQfRcDzL3uStsRmrx3qi8DvM62nlsfWJpe7JCUKXgnQIDAQAB
-----END PUBLIC KEY-----`;


